import axios from 'axios'
import { RootThunkAction } from '../../types/store'
import { getAricleList } from './article'
// 获取频道信息
export const getChannels = (): RootThunkAction => {
  return async (dispatch) => {
    const res = await axios.get('http://geek.itheima.net/v1_0/channels')
    // console.log(res)
    dispatch({ type: 'channel/get', payload: res.data.data.channels })
  }
}

// 切换频道高亮/切换文章来源数据
export const toggleChannels = (id: number): RootThunkAction => {
  return (dispatch) => {
    dispatch({ type: 'channel/toggle', payload: id })
    // 重新获取相关文章数据
    dispatch(getAricleList(id))
  }
}
